package com.example.nbshangpping.History;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;

import com.example.nbshangpping.R;
import com.example.nbshangpping.login.UserBean;
import com.example.nbshangpping.utils.BaseActivity;
import com.example.nbshangpping.utils.SaveUserUtils;
import com.example.nbshangpping.utils.URLUtils;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;

public class HistoryActivity extends BaseActivity {
    private ImageView backIv;
    ListView lv;
    List<HistoryBean.DataBean>data;
    private HistoryAdapter adapter;
    private UserBean.DataBean userInfo;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_history);
        userInfo= SaveUserUtils.getUserInfo(this);//获取到保存的登录信息
        initView();
        //适配器
        data=new ArrayList<>();
        adapter = new HistoryAdapter(this, data);
        lv.setAdapter(adapter);
        //联网
        getNetwork(URLUtils.querybougth_url+userInfo.getId());
    }


    private void initView() {
        backIv=findViewById(R.id.history_iv_back);
        lv=findViewById(R.id.cart_lv);
        backIv.setOnClickListener(onClickListener);
//        lv.setOnItemClickListener(listener);
    }



    @Override
    public void onSuccess(String result) {
        super.onSuccess(result);
        HistoryBean historyBean = new Gson().fromJson(result, HistoryBean.class);
        List<HistoryBean.DataBean> list = historyBean.getData();
        data.clear();
        data.addAll(list);
        adapter.notifyDataSetChanged();
    }

//    AdapterView.OnItemClickListener listener=new AdapterView.OnItemClickListener() {
//        @Override
//        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//            HistoryBean.DataBean dataBean= data.get(position);
//            Intent intent=new Intent(HistoryActivity.this, DetailsGoodsActivity.class);
//            intent.putExtra("goods",dataBean);//将数据传递给下一级页面
//            startActivity(intent);
//        }
//    };
    View.OnClickListener onClickListener=new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    };
}